package com.teacher.pc.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.teacher.common.CommonResult;
import com.teacher.pojo.dto.moraleducationbasic.MoralEducationBasicGetDto;
import com.teacher.pojo.dto.moraleducationbasic.MoralEducationBasicUpdateDto;
import com.teacher.pojo.entity.MoralEducationBasic;
import com.teacher.pojo.vo.moraleducationbaisc.MoralEducationBasicGetVo;
import com.teacher.service.IMoralEducationBasicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 德育基础分 前端控制器
 * </p>
 *
 * @author zfm
 * @since 2021-08-05
 */
@RestController
@RequestMapping("/pc/moral-education-basic")
@Api(tags = "德育基本分")
public class MoralEducationBasicController {

    @Autowired
    private IMoralEducationBasicService iMoralEducationBasicService;

    /**
     * 初始化基础德育分
     *
     * @param classId
     * @return
     */
    @PostMapping("/{classId}")
    @ApiOperation("初始化基础德育分 moralEducation_initialize")
    @PreAuthorize("hasAuthority('moralEducation_initialize')")
    public CommonResult<String> init(@PathVariable("classId") Long classId) {
        return iMoralEducationBasicService.init(classId);
    }

    /**
     * 更新德育基础分
     *
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("更新德育基础分 moralEducation_update")
    @PreAuthorize("hasAuthority('moralEducation_update')")
    public CommonResult<String> update(@RequestBody @Validated MoralEducationBasicUpdateDto dto) {
        MoralEducationBasic moralEducationBasic = new MoralEducationBasic();
        BeanUtils.copyProperties(dto, moralEducationBasic);
        if (iMoralEducationBasicService.updateById(moralEducationBasic)) {
            return CommonResult.success("更新成功");
        }
        return CommonResult.failed("更新失败");
    }

    /**
     * 查询德育基本分
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询德育基本分 moralEducation_get")
    @PreAuthorize("hasAuthority('moralEducation_get')")
    public CommonResult<IPage<MoralEducationBasicGetVo>> getPage(MoralEducationBasicGetDto dto) {
        return iMoralEducationBasicService.getPage(dto);
    }

}

